package com.jiutong.meipenggang.ui.activitys;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.base.AppManager;
import com.jiutong.meipenggang.base.BaseActivity;
import com.jiutong.meipenggang.base.CommonAdapter;
import com.jiutong.meipenggang.base.ViewHolder;
import com.jiutong.meipenggang.entity.InvestRecordBean;
import com.jiutong.meipenggang.http.model.interfaces.InvestRecordBiz;
import com.jiutong.meipenggang.http.present.InvestRecordPresent;
import com.jiutong.meipenggang.views.MyListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * @author Veken
 *         作用：投资记录
 */
public class InvestRecordActivity extends BaseActivity implements InvestRecordBiz {


    @Bind(R.id.rl_common_title_back)
    RelativeLayout rlCommonTitleBack;
    @Bind(R.id.tv_common_title)
    TextView tvCommonTitle;
    @Bind(R.id.invest_recode_list_view)
    MyListView investRecodeListView;
    @Bind(R.id.tv_invest_record_user_one)
    TextView tvInvestRecordUserOne;
    @Bind(R.id.tv_invest_record_money_one)
    TextView tvInvestRecordMoneyOne;
    @Bind(R.id.tv_invest_record_user_two)
    TextView tvInvestRecordUserTwo;
    @Bind(R.id.tv_invest_record_money_two)
    TextView tvInvestRecordMoneyTwo;
    @Bind(R.id.tv_invest_record_user_three)
    TextView tvInvestRecordUserThree;
    @Bind(R.id.tv_invest_record_money_three)
    TextView tvInvestRecordMoneyThree;
    private InvestRecordAdapter adapter;
    private List<InvestRecordBean.ListBean> mlist = new ArrayList<>();
    private InvestRecordPresent investRecordPresent;
    private List<InvestRecordBean.TopListBean> topList = new ArrayList<>();
    private int bidId;

    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_invest_record;
    }

    @Override
    protected void initView() {
        super.initView();
        tvCommonTitle.setText("投资记录");

        Bundle bundle = getIntent().getExtras();
        int bidId = bundle.getInt("bidId");
        if(bidId<=0){
            return;
        }

        investRecordPresent = new InvestRecordPresent(this, this);
        investRecordPresent.getInvestRecordInfo();

    }

    @OnClick(R.id.rl_common_title_back)
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_common_title_back:
                AppManager.getAppManager().finishActivity(this);
                break;
            default:
        }
    }

    @Override
    public int bidId() {
        return bidId;
    }

    @Override
    public String currPage() {
        return "1";
    }

    @Override
    public void onSuccess(Object object) {
        InvestRecordBean bean = (InvestRecordBean) object;
        if (bean.getError() == -1) {
            mlist = bean.getList();
            topList = bean.getTopList();
            if(mlist.size()>0){
                adapter = new InvestRecordAdapter(this, mlist, R.layout.item_invest_record);
                investRecodeListView.setAdapter(adapter);
            }else{
                toastShortShow("没有投资记录");
            }
//            tvInvestRecordMoneyOne.setText(topList.get());
        }
    }

    @Override
    public void onError(Throwable e) {
    }

    @Override
    public int getOpt() {
        return 56;
    }


    public class InvestRecordAdapter extends CommonAdapter<InvestRecordBean.ListBean> {

        public InvestRecordAdapter(Context context, List<InvestRecordBean.ListBean> listDatas, int layoutId) {
            super(context, listDatas, layoutId);
        }

        @Override
        protected void fillData(ViewHolder holder, int position) {
            TextView tvItemInvestRecordUser = holder.getView(R.id.tv_item_invest_record_user);
            TextView tvItemInvestRecordMoney = holder.getView(R.id.tv_item_invest_record_money);
            TextView tvItemInvestRecordDay = holder.getView(R.id.tv_item_invest_record_day);
            TextView tvItemInvestRecordHour = holder.getView(R.id.tv_item_invest_record_hour);
            LinearLayout llIitem = holder.getView(R.id.rl_item_invest_record);
            if (position % 2 == 0) {
                llIitem.setBackgroundColor(mContext.getResources().getColor(R.color.bg_light_gray));
            } else {
                llIitem.setBackgroundColor(Color.WHITE);
            }
            tvItemInvestRecordUser.setText(listDatas.get(position).getName());
            tvItemInvestRecordMoney.setText(listDatas.get(position).getAmount());
            String time = listDatas.get(position).getTime();
            String[] strings = time.split(" ");
            tvItemInvestRecordDay.setText(strings[0]);
            tvItemInvestRecordHour.setText(strings[1]);
        }

    }
}

